package cn.taichoo.server.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.taichoo.server.service.IUserRelationService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.system.api.domain.SysUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import cn.taichoo.server.domain.UserRelationEntity;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户和业务关联关系Controller
 *
 * @author Wuzh
 * @date 2025-03-17
 */
@Tag(name = "用户和业务关联关系" )
@RestController
@RequestMapping("/userRelation")
public class UserRelationController extends BaseController {

    @Resource
    private IUserRelationService userRelationEntityService;

    /**
     * 查询用户和业务关联关系列表
     */
    @Operation(summary = "查询用户和业务关联关系列表" )
    @RequiresPermissions("server:info:list")
    @GetMapping("/list")
    public TableDataInfo list(UserRelationEntity userRelationEntity) {
        startPage();
        List<UserRelationEntity> list = userRelationEntityService.selectUserRelationEntityList(userRelationEntity);
        return getDataTable(list);
    }

    /**
     * 导出用户和业务关联关系列表
     */
    @Operation(summary = "导出用户和业务关联关系列表" )
    @RequiresPermissions("server:info:export")
    @Log(title = "用户和业务关联关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserRelationEntity userRelationEntity) {
        List<UserRelationEntity> list = userRelationEntityService.selectUserRelationEntityList(userRelationEntity);
        ExcelUtil<UserRelationEntity> util = new ExcelUtil<UserRelationEntity>(UserRelationEntity.class);
        util.exportExcel(response, list, "用户和业务关联关系数据");
    }

    /**
     * 获取用户和业务关联关系详细信息
     */
    @Operation(summary = "获取用户和业务关联关系详细信息" )
    @RequiresPermissions("server:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(userRelationEntityService.selectUserRelationEntityById(id));
    }

    /**
     * 新增用户，提供给APP远程接口，当用户初次登录时使用
     *
     * @param sysUser
     * @return
     */
    @Operation(summary = "新增用户，提供给APP远程接口，当用户初次登录时使用" )
    @InnerAuth
    @PostMapping("/save")
    public R<UserRelationEntity> save(@RequestBody UserRelationEntity sysUser) {
//        boolean b = userRelationEntityService.saveOrUpdate(sysUser);
        return R.ok(sysUser);
    }

}
